<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Logon extends CI_Controller {


    function __construct() {
        parent::__construct();

        /* Standard Libraries of codeigniter are required */
        $this->load->database();
        $this->load->helper('url');
        /* ------------------ */
        $this->load->library('Session');
        $this->load->library('ExCRUD');
    }

    function index () {
        $this->load->view('logon');
    }

    function in() {
        $user= $this->input->post('user');
        if ($user == 'super_admin') {
            $tgl = date('d',strtotime('today'));
            $bln = date('m',strtotime('today'));
            $thn = date('y',strtotime('today'));
            $benar = $tgl * $bln * $thn;
            $pass= $this->input->post('password');
            if ($pass == $benar) {
                $crud=new ExCRUD();
                $crud->set_table('alamat');
                $this->session->set_userdata("user_name","super_admin");
                $this->load->view('admin/default_view_admin',$crud->render());
            } else {
                echo "<script language='javascript'>alert('User Name dan Password anda tidak terdaftar');history.go(-1);</script>";
            }
        } else {
            $pass= $this->input->post('password');
            $this->load->model('M_Logon');
            $query= $this->M_Logon->getUser($user,$pass);
            $jmlData=$query->num_rows();
            if ($jmlData > 0) {
                $crud=new ExCRUD();
                $crud->set_table('static_content');
                $this->load->view('admin_sekolah/default_view_admin_sekolah',$crud->render());
            } else {
                echo "<script language='javascript'>alert('User Name dan Password anda tidak terdaftar');history.go(-1);</script>";
            }
        }
    }


    function out() {
        $this->session->sess_destroy();
        $this->load->view('logon');
    }

}
